package com.as.yiznspringbootstarter;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * project : my-learn
 * <p> 自动配置类 </p>
 *
 * @author yisl
 * @date 2022-06-14【星期二】
 **/
@Configuration
@ConditionalOnClass(SplicingService.class)
@EnableConfigurationProperties(SplicingServiceProperties.class)

public class SplicingAutoConfiguration {
    @Resource
    private SplicingServiceProperties properties;

    @Bean
    @ConditionalOnProperty(name="splicing.service.enabled", havingValue = "true")
    public SplicingService splicingService1(){
        return new SplicingService("", "");
    }

    @Bean
    @ConditionalOnMissingBean
    public SplicingService splicingService(){
        return new SplicingService(properties.getPrefix(), properties.getSuffix());
    }
}
